<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
/**
* 
* @author DANG DINH HUNG
*
*/
class Authorization extends Public_Controller
{
	
	public function __construct()
	{
		parent::__construct();
		$this->load->model('authorization_m'); 
		
		if( ENVIRONMENT != 'development' ){
			force_ssl();
		}
	}
	
	public function index()
	{
	 	redirect( site_url_lang("authorization/login") );
	}
	
	// for escort | agent
	function login(){
		$this->template->title( language_translate('brower_title_login') );
		$this->template
			->build('escort_login_page');
	}
	
	function forgot_details(){
		$this->template->title( language_translate('brower_title_forgot_details') );
		$this->template
			->build('forgot_details');
	}
	
	function submit_forgot_details(){
		$this->authorization_m->submit_forgot_details();
		exit();
	}
	
	function submit_escort_login(){
		$this->authorization_m->submit_escort_login();
		exit();
	}
	
	function login_confirm(){
		if(!isLogin()){
			redirect( site_url_lang("home") );
		}
		
		switch(getPermission()){
			case 'escort':
			default:
				$link = site_url_lang("escorts/profile");
				break;
			case 'agent':
				$link = site_url_lang("agent/my_profile");
				break;
		}
		redirect($link);
	}
	
	function logout(){
		$USER = getAccountUserObject();
		$this->action_log->insertNewAction($USER->getId(),'log_action_logout');
		
		$this->session->unset_userdata('account');
		redirect( site_url_lang("home") );
	}
	
	function email_confirm(){
		$id = $this->input->get('id',TRUE);
		$s = $this->input->get('s',TRUE);
		$USER = $this->user_entity->init('id',$id);
		if(!$USER){
			show_404();
			exit;
		}
		if(md5($USER->getUserName()) != $s){
			show_404();
			exit;
		}
		$USER->setEmail($USER->getEmailChanged());
		$USER->update();
		
		$this->template
			->build('email_confirm');
	}
	
	
	
	
	//end class
}